﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SafetyRecord
{
    public partial class RecordControl : UserControl
    {
        public RecordControl(int index)
        {
            InitializeComponent();
            this.recordBox.Text = "笔录内容" + index.ToString();
        }

        public void InitComboBoxValue(Dictionary<string, List<string>> wentiDict, Dictionary<string, List<string>> daanDict)
        {

            foreach (KeyValuePair<string, List<string>> kv in wentiDict)
            {
                ComboBox combo = (ComboBox)this.tableLayoutPanel.Controls[kv.Key];
                if (kv.Value.Count > 0)
                {
                    combo.Items.Clear();
                    foreach (string item in kv.Value)
                    {
                        combo.Items.Add(item);
                    }
                    combo.Items.Add("问：");
                }
            }

            foreach (KeyValuePair<string, List<string>> kv in daanDict)
            {
                ComboBox combo = (ComboBox)this.tableLayoutPanel.Controls[kv.Key];
                if (kv.Value.Count > 0)
                {
                    combo.Items.Clear();
                    foreach (string item in kv.Value)
                    {
                        combo.Items.Add(item);
                    }
                    combo.Items.Add("答：");
                }
            }
        }

        //获取ComboBox值
        public Dictionary<string, Dictionary<int, string>> GetComboBoxs()
        {
            Dictionary<string, Dictionary<int, string>> item = new Dictionary<string, Dictionary<int, string>>();
            ComboBox combo = null;
            Dictionary<int, string> wenti = new Dictionary<int, string>();
            Dictionary<int, string> daan = new Dictionary<int, string>();
            foreach (Control b in this.tableLayoutPanel.Controls)
            {
                if (b is ComboBox)
                {
                    combo = (ComboBox)b;
                    if (combo.Name.StartsWith("wenti"))
                    {
                        wenti.Add(int.Parse(combo.Name.Substring(5)), combo.Text.Trim());
                    }
                    else if (combo.Name.StartsWith("daan"))
                    {
                        daan.Add(int.Parse(combo.Name.Substring(4)), combo.Text.Trim());
                    }
                }
            }
            Dictionary<int, string> wentiAsc = wenti.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
            Dictionary<int, string> daanAsc = daan.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
            item.Add("wenti", wentiAsc);
            item.Add("daan", daanAsc);
            return item;
        }

        //设置ComboBox值
        public void SetComboBoxValues(Dictionary<string, string> dict)
        {
            foreach (KeyValuePair<string, string> kv in dict)
            {
                ComboBox combo = (ComboBox)this.tableLayoutPanel.Controls[kv.Key];
                combo.Text = kv.Value;
            }
        }
    }
}
